package gui.lesson02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestActionEvent {
    public static void main(String[] args) {
        initview();
    }

    private static void Windowcolse(Frame frame) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    private static void initview() {
        Frame frame = new Frame("TestActionEvent");
        Button button = new Button("hello GUI");
        frame.setBackground(Color.pink);
        frame.setBounds(200,200,400,400);
        frame.setVisible(true);
        frame.add(button,BorderLayout.CENTER);
        Windowcolse(frame);
        MyActionListener myActionListener = new MyActionListener();
        button.addActionListener(myActionListener);

    }
static class MyActionListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("点击按钮我就出现了");
    }
}
}
